var role = require("../lib/role");
module.exports = {
	prefix: "/admin_blog",
	get: {
		//分页返回用户自己的博文列表信息，包括分页信息
		"/list": function() {
			var admin = role.getAdmin(this);
			var query = this.request.query;
			var blog_list_info = admin.getBlogList(query.type, query.num, query.page);
			this.body = ResponObj("json", blog_list_info);
		},
		"/by_id/:blog_id": function() {
			var admin = role.getAdmin(this);
			var blog_id = this.params.blog_id;
			var blog = admin.getBlog(blog_id);
			this.body = ResponObj("json", blog.getDetail());
		}
	},
	put: {
		"/update_blog": function() {
			var admin = role.getAdmin(this);
			var blog_info = this.request.body;
			var blog = admin.updateBlog(blog_info._id, blog_info);
			this.body = ResponObj("json", blog);
		}
	},
	delete: {
		"/delete_blog/:blog_id": function() {
			var admin = role.getAdmin(this);
			var blog_id = this.params.blog_id;
			var body = this.request.body;
			admin.removeBlog(blog_id);
			if (body.back_list) { //以列表信息返回
				var blog_list_info = admin.getBlogList(body.type, body.num, body.page);
				this.body = ResponObj("json", blog_list_info);
			} else {
				this.body = ResponObj("string", "博文删除成功");
			}
		}
	}
}